package com.quanyan.search.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * CommonUtil
 *
 * @author Tu Chun
 * @date 2016/6/14
 */
public class CommonUtil {
//    private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
//    private final static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//    private final static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
    private final static String _startTime = "00:00:00";
    private final static String _endTime = "24:00:00";

    public static boolean isNullOrZero(Integer num) {
        if (null == num) return true;
        return num == 0;
    }

    public static boolean isNullOrZero(List list) {
        if (null == list) return true;
        return list.size() == 0;
    }
    public static String getLatLng(double lat, double lng) {
        return lat + "," + lng;
    }

    public static String getSolrDate(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String solrDate = sdf.format(sdf2.parse(date));
        return solrDate;
    }
    public static String getSolrDate(Date date) throws ParseException {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String solrDate = getSolrDate(sdf2.format(date));
        return solrDate;
    }
    public static String getDate(Date date) throws ParseException {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String solrDate = sdf2.format(date);
        return solrDate;
    }
    public static String getFormatDate(String solrDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatDate = sdf2.format(sdf.parse(solrDate));
        return formatDate;
    }
    public static String getFormatDate(Date reqDate) throws ParseException {
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
        String formatDate = sdf3.format(reqDate);
        return formatDate;
    }
    public static Date getFormatDateByLong(Long solrTime) throws ParseException {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatDate = sdf2.format(solrTime - (long) (8 * 60 * 60 * 1000));
        return getDateByStr(formatDate);
    }

    public static Date getDateByStr(String dateStr) throws ParseException {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf2.parse(dateStr);
    }

    public static String getSolrDateScope(String date) throws ParseException {
        String startDate = getSolrDate(date + " " + _startTime);
        String endDate = getSolrDate(date + " " + _endTime);
        String dateScope = "[" + startDate + " TO " + endDate + "]";
        return dateScope;
    }

    public static String getSolrDateScope2(String solrDate) throws ParseException {
        String dateScope = "[" + solrDate + " TO " + solrDate + "]";
        return dateScope;
    }
    public static String getSolrDateScope3(String startTime,String endTime) throws ParseException {
        String dateScope = "[" + startTime + " TO " + endTime + "]";
        return dateScope;
    }

    public static String getDateTime(String date, String time) {
        return date + " " + time;
    }

    /*public static void main(String[] args) throws ParseException {

        String str= getSolrDate(new Date());
        System.out.println(str);

    }*/
}
